package LeetCode.month03.day88;

/**
 * @author 16778
 * @date 2025/10/28 8:26
 * @description
 */
public class No3354 {
    public int countValidSelections(int[] nums) {
        int res = 0;
        int n = nums.length;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum+=nums[i];
        }
        int x = sum/2;
        int y = (sum+1)/2;
        int sum2 = 0;
        for (int i = 0; i < n; i++) {
            sum2+=nums[i];
            if(nums[i]==0) {
                if (sum2 == x) res++;
                if (sum2 == y) res++;
                if (sum2 > Math.max(x, y)) return res;
            }
        }
        return res;
    }
}
